import json
import re

def getData():
    allsite = []
    with open("site.json",'r',encoding="utf-8") as f:
        line = f.readline()
        while line:
            if line != None:
                content = line.lstrip().replace(" ","").replace(",","")
                if content.find("cdtf") > 0:
                    pattern = r'\"(.*?)\"'
                    matches = re.findall(pattern, content)
                    allsite.append(matches[1])
            line = f.readline()
        return allsite

allsit = getData()
i = 1
for site in allsit:
    piece = str(site).split("/")
    str1 = '["'+str(site)+'"]="rtmp://192.168.28.125:1935/live/'+piece[3]+'"'
    #str2 = 'sleep 3\n'
    #str2 = '/usr/bin/ffmpeg -rtsp_transport tcp -i '+str(site)+' -c:v libx264 -an -f flv rtmp://192.168.28.125:1935/live/'+piece[3]+' &'
    str2 = '/usr/bin/ffmpeg -i http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8 -c:v libx264 -an -f flv rtmp://192.168.0.4:1935/live/'+piece[3]+' &'
    #str2 = '/usr/bin/ffmpeg -i http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8 -hls_wrap 10 -c copy -f hls -rtmp_live live -rtmp_keepalive 10 /tmp/' + piece[3] + '.m3u8 &'
    #str2 = 'nohup /usr/bin/ffmpeg -nostdin -re -rtsp_transport tcp -i '+str(site)+' -hls_wrap 10 -c copy -f hls /tmp/'+piece[3]+'.m3u8 >> /dev/null 2>&1 &'

    #print(str1)
    print(str2)
    i += 1

#["rtsp://xxxx:xxxx@xxxx:554/h264/ch1/main/av_stream"]="rtmp://xxxxx:1935/live/D0"